package com.hzp.lolnews.ui.news.view;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.hzp.lolnews.R;
import com.hzp.lolnews.bean.HomeContent;

import java.util.List;

/**
 * Created by Administrator on 2016/10/20 0020.
 */
public class ContentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    public static final int TYPE1 = 1;
    public static final int TYPE2 = 2;
    public static final int TYPE3 = 3;

    private List<HomeContent> list;



    public void setData(List<HomeContent> image) {
        this.list = image;
        notifyDataSetChanged();
    }



    @Override
    public int getItemViewType(int position) {
        HomeContent homeContent = list.get(position);
        String article_channel_id = homeContent.getArticle_channel_id();
        int i = Integer.parseInt(article_channel_id);
        if (i == 1 || i == 5) {
            return 1;
        } else if (i == 11) {
            return 2;
        }{
            return 3;
        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;
        if (viewType == TYPE1) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_ltem_commen, parent, false);
            ViewHolderShop1 shop1 = new ViewHolderShop1(view);
            return shop1;

        } else if (viewType == TYPE2) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_special, parent, false);
            ViewHolderShop2 shop2 = new ViewHolderShop2(view);
            return shop2;

        } else if (viewType == TYPE3) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_other, parent, false);
            ViewHolderShop3 shop3 = new ViewHolderShop3(view);
            return shop3;

        }
        return null;
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
        HomeContent homeContent = list.get(position);
        if (holder instanceof ViewHolderShop1){
            ((ViewHolderShop1) holder).simpleDraweeView.setImageURI(homeContent.getArticle_pic());
            ((ViewHolderShop1) holder).tvPin.setText(homeContent.getArticle_comment());
            ((ViewHolderShop1) holder).tvTitle.setText(homeContent.getArticle_title());
            ((ViewHolderShop1) holder).tvSource.setText(homeContent.getArticle_mall());
            ((ViewHolderShop1) holder).tvTime.setText(homeContent.getArticle_date());
            ((ViewHolderShop1) holder).tvZhi.setText(homeContent.getArticle_worthy());
        }else if (holder instanceof ViewHolderShop2){
            ((ViewHolderShop2) holder).simpleDraweeView.setImageURI(homeContent.getArticle_pic());
            ((ViewHolderShop2) holder).sName.setText(homeContent.getArticle_title());
            ((ViewHolderShop2) holder).sTime.setText(homeContent.getArticle_date());
            ((ViewHolderShop2) holder).sType.setText(homeContent.getArticle_channel_name());
        }else if (holder instanceof ViewHolderShop3){
            ((ViewHolderShop3) holder).otherSimple.setImageURI(homeContent.getArticle_pic());
            ((ViewHolderShop3) holder).otherPin.setText(homeContent.getArticle_comment());
            ((ViewHolderShop3) holder).otherSource.setText(homeContent.getArticle_mall());
            ((ViewHolderShop3) holder).otherTime.setText(homeContent.getArticle_date());
            ((ViewHolderShop3) holder).otherTitle.setText(homeContent.getArticle_title());
            ((ViewHolderShop3) holder).otherZhi.setText(homeContent.getArticle_worthy());
            ((ViewHolderShop3) holder).otherPrice.setText(homeContent.getArticle_price());

        }

    }

    @Override
    public int getItemCount() {
        return list.size() != 0 ? list.size() : 0;
    }

    class ViewHolderShop1 extends RecyclerView.ViewHolder {

        private final SimpleDraweeView simpleDraweeView;
        private final TextView tvPin,tvSource,tvTime,tvTitle,tvZhi;

        public ViewHolderShop1(View itemView) {
            super(itemView);
            simpleDraweeView = (SimpleDraweeView) itemView.findViewById(R.id.commen_simpleDraweeView);
            tvPin = (TextView) itemView.findViewById(R.id.commen_tvPin);
            tvSource = (TextView) itemView.findViewById(R.id.commen_tvSource);
            tvTime = (TextView) itemView.findViewById(R.id.commen_tvTime);
            tvTitle = (TextView) itemView.findViewById(R.id.commen_tvTitle);
            tvZhi = (TextView) itemView.findViewById(R.id.commen_tvZhi);
        }
    }

    class ViewHolderShop2 extends RecyclerView.ViewHolder {

        private final SimpleDraweeView simpleDraweeView;
        private final TextView sTime,sName,sType;

        public ViewHolderShop2(View itemView) {
            super(itemView);
            simpleDraweeView = (SimpleDraweeView) itemView.findViewById(R.id.special_simpleDraweeView);
            sTime = (TextView) itemView.findViewById(R.id.special_time);
            sName = (TextView) itemView.findViewById(R.id.special_tvName);
            sType = (TextView) itemView.findViewById(R.id.special_tvType);

        }
    }

    class ViewHolderShop3 extends RecyclerView.ViewHolder {


        private final SimpleDraweeView otherSimple;
        private final TextView otherPin,otherSource,otherTime,otherTitle,otherZhi,otherPrice;

        public ViewHolderShop3(View itemView) {
            super(itemView);
            otherSimple = (SimpleDraweeView) itemView.findViewById(R.id.other_simpleDraweeView);
            otherPin = (TextView) itemView.findViewById(R.id.other_tvPin);
            otherSource = (TextView) itemView.findViewById(R.id.other_tvSource);
            otherTime = (TextView) itemView.findViewById(R.id.other_tvTime);
            otherTitle = (TextView) itemView.findViewById(R.id.other_tvTitle);
            otherZhi = (TextView) itemView.findViewById(R.id.other_tvZhi);
            otherPrice = (TextView) itemView.findViewById(R.id.other_tvPrice);
        }
    }
}
